<?php
require_once('../model/Db.php');
require_once('../model/Mail.php');
$Db = Db::getInstance();
$Mail = Mail::getInstance();
if($_POST['email'] && $_POST['user']){
	$vcode = substr(str_shuffle('000111222333444555666777888999'),0,6);
	$mail_flag = $Mail->send([
		toemail => $_POST['email'],
		toname => $_POST['user'],
		subject => '青柠密码安全',
		body => "您正在进行密码修改操作,验证码是{$vcode},2分钟内有效,如非本人操作请忽略本信息"
	]);
	if($mail_flag){
		setcookie('usable',time(),time()+120,'/nsbbs');
		$_SESSION['vcode'] = $vcode;
	}
	echo json_encode([success=>$mail_flag]);
}else{
	http_response_code(404);
	echo '<h1 style="color:#337ab7">千呼万唤始出来,犹抱琵琶半遮面</h1>';
}